package com.example.aliyun.plus;
class MyRunnable implements Runnable{

    String title;
    public MyRunnable(String title) { // 构造函数
        this.title = title;
    }
    @Override
    public void run() { // 覆写run() 方法
        for (int i = 0; i < 10; i++) {
            System.out.println(this.title + " is Running"+ "------->" + i);
        }

    }
}

public class RunnableDemo {
    public static void main(String[] args) {
        /*
        MyRunnable runnable1 = new MyRunnable("Thread-001");
        MyRunnable runnable2 = new MyRunnable("Thread-002");
        MyRunnable runnable3 = new MyRunnable("Thread-003");
        new Thread(runnable1).start(); // Runnable 接口实现类实例需要作为Thread 类的参数调用start() 方法
        new Thread(runnable2).start();
        new Thread(runnable3).start();
         */
        for (int i = 0; i < 3; i++) {
            new Thread(()->{
                for (int j = 0; j < 10; j++) {
                    String title = "thread---" + j;
                    System.out.println(title + " is running");
                }
            }).start();
        }
    }
}
